<%@Page Language="VB"%>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.SqlClient" %>
<html><head>
<title>
The .NET DataSet and 
SqlDataAdapter Objects</title>
</head>
<body>
<span class="heading">DataTable and DataView Objects</span>
<hr width="350" align="left"/>
<div id="outError" runat="server">&nbsp;</div>
<br />
DataTable Object<br />
<asp:datagrid id="dgrResultTable" runat="server" /> 
<br />
DataView Object<br />
<asp:datagrid id="dgrResultView" runat="server" /> 
<script language="vb" runat="server">
Private myDataSet As DataSet 
Dim myDataView As DataView
Sub Page_Load(ByVal sender As Object, _
ByVal e As EventArgs)      
   MakeTable()   
   dgrResultTable.DataSource = myDataSet
   dgrResultView.DataSource = myDataView
   dgrResultTable.DataBind()   
   dgrResultView.DataBind()   
End Sub
Private Sub MakeTable()  
    Dim myDataTable As DataTable = new DataTable("tblCustomers")
    Dim myDataColumn As DataColumn 
    Dim myDataRow As DataRow 
    myDataColumn = New DataColumn()
    myDataColumn.DataType = System.Type.GetType("System.Int32")
    myDataColumn.ColumnName = "Custid"
    myDataColumn.ReadOnly = True
    myDataColumn.Unique = True
    myDataTable.Columns.Add(myDataColumn)

    myDataColumn = New DataColumn()
    myDataColumn.DataType = System.Type.GetType("System.String")
    myDataColumn.ColumnName = "CustName"
    myDataColumn.AutoIncrement = False
    myDataColumn.Caption = "CustName"
    myDataColumn.ReadOnly = False
    myDataColumn.Unique = False
    myDataTable.Columns.Add(myDataColumn)

    myDataColumn = New DataColumn()
    myDataColumn.DataType = System.Type.GetType("System.String")
    myDataColumn.ColumnName = "Email"
    myDataColumn.AutoIncrement = False
    myDataColumn.Caption = "Email"
    myDataColumn.ReadOnly = False
    myDataColumn.Unique = False
    myDataTable.Columns.Add(myDataColumn)

    Dim PrimaryKeyColumns(0) As DataColumn
    PrimaryKeyColumns(0)= myDataTable.Columns("Custid")
    myDataTable.PrimaryKey = PrimaryKeyColumns
    myDataSet = New DataSet()    
    myDataSet.Tables.Add(myDataTable)
    Dim i As Integer
    For i = 0 to 3
       myDataRow = myDataTable.NewRow()
       myDataRow("Custid") = i
       myDataRow("CustName") = "Company ABC " + i.ToString()
       myDataRow("Email") = "Email of Company is " + i.ToString()
       myDataTable.Rows.Add(myDataRow)
    Next i
    myDataView = New DataView(myDataTable)
    With myDataView
       .RowFilter = "CustID>1"
       .Sort = "CustName DESC"
    End With
 End Sub
</script>
</body>
</html>
  